package com.hotdog.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hotdog.mapper.PayMapper;
import com.hotdog.mapper.UserMapper;
import com.hotdog.mapper.UserRoleMapper;
import com.hotdog.pojo.PayInfo;
import com.hotdog.pojo.User;
import com.hotdog.pojo.UserRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class PayServiceImpl implements PayService{
    @Autowired
    private UserMapper userMapper;
@Autowired
private PayMapper payMapper;
@Autowired
private UserRoleMapper userRoleMapper;
    @Override
    public void insertPayUser(String username,String orderid) {
        PayInfo payInfo = new PayInfo();
        payInfo.setUsername(username).setOrderid(orderid);
        payMapper.insert(payInfo);
    }

    @Override
    public void updateInfo(String money, String orderid) {
        QueryWrapper<PayInfo> payInfoQueryWrapper = new QueryWrapper<>();
        payInfoQueryWrapper.eq("orderid", orderid);


        PayInfo payInfo = payMapper.selectOne(payInfoQueryWrapper);
        payMapper.updateById(new PayInfo().setStates("已支付").setId(payInfo.getId()));
        log.error(payInfo+"error");
        String username = payInfo.getUsername();
        User user = userMapper.selectOne(new QueryWrapper<User>().eq("username", username));
        log.error(user.toString());
        UserRole userId = userRoleMapper.selectOne(new QueryWrapper<UserRole>().eq("user_id", user.getId()));
        userId.setRoleId(1);
        log.error(userId.toString());
        userRoleMapper.updateById(userId);


    }
}
